<?php
namespace app\index\controller;

use \think\Controller;
//use think\facade\Request;
use think\Db;
use think\facade\Request;
use app\index\controller\Base;
class Car extends  Base
{
	public function index()
	{
		$car = Db::table('shop_car')
		->field('shop_car.goods_num as goods_num,shop_car.goods_id as goods_id,shop_car.goods_style as style_id,goods_color,goods_thumb,shop_car.id as id,sum(shop_car.goods_num),shop_goods.goods_name,shop_goods_detail.goods_price')
		->join('shop_goods','shop_goods.id=shop_car.goods_id','left')
		->join('shop_goods_detail','shop_goods_detail.id=shop_car.goods_style','left')
		->where('shop_car.goods_status',0)
		->where('shop_car.user_id',session('userinfo')['id'])
		->group('shop_car.goods_style')
		->select();
		
		$this->assign('car',$car);
//		dump($car);exit;
		return $this->fetch();
	}
	public function addcar()
	{
		$post = input('post.');
		$addcar = Db::table('shop_car')->insert([
		'goods_id'=>$post['buy_id'],
		'goods_style'=>$post['buy_style'],
		'goods_num'=>$post['buy_num'],
		'user_id'=>session('userinfo')['id'],
		'goods_status'=>0
		]);
		if($addcar>0)
		{
			echo 40000;	
		}else
		{
			echo 40001;
		}
		
	}
	public function confirmorder()
	{
		$post = input('post.');
		
		$arr = $post['str'];
		$arr = json_decode($arr);
		$data = Array();
		$order_num = time().mt_rand(10000,99999);
		foreach($arr as $k=>$v)
		{
			$arr = Array();
			$arr['goods_id'] = $v[0];
			$arr['style_id'] = $v[1];
			$arr['goods_num'] = $v[2];
			$arr['status'] = 0;
			$arr['odernum'] = $order_num;
			$data[] = $arr;
		}
		Db::name('order')->insertAll($data);
		echo json_encode([40000,$order_num]);
//		echo $order_num;
	}
	public function suborder()
	{
		$ordernum = input('odernum');
		session('ordernum',$prdernum);
		echo $ordernum;
	}
}
	